<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/m/include/init_mobile.jsp" %>
<%
	
	String book_code		= StringUtil.nvl(request.getParameter("book_code"));

	StoreDAO dao = new StoreDAO();
	HashList categoryList 	= dao.selectCategoryList(new HashMap());
%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
	<title><%= HOME_NAME %></title>
	<%@ include file="/m/include/cssnjs.jsp"  %>
	<link rel="stylesheet" href="/css/jquery.mobile-1.4.2.min.css"/>
	<script type="text/javascript">
	$(document).ready(function() {
		$('#header-nav li:nth-child(3)').addClass('on');
	});
	
	function fnSearchCoupon() {
		if (<%=isLogin%> == false) {
			cfShowModalConfirm('로그인하시겠습니까?');
			return false;
		}
		
		if (document.searchForm.coupon_no.value == "") {
			cfShowModal("쿠폰번호를 입력하세요");	
			return false;
		}
		
		$.ajax({
			url: '/store/book/couponPurchase.do',
			type: "POST",
		    dataType: 'json',
		    data:{ 
		    	os_type 	: "<%=os%>",
		    	coupon_no	: $('#coupon_no').val()
		    },
		    error: function(data, status, err){
		    	cfShowModal(err);
		    },
			success: function(data){
				if (data.result) {
					$('#coupon_no').val("");
					cfShowModal("쿠폰이 확인되었습니다.\n내서재에서 새로고침하신 후 다운로드 받으세요");
				} else {
					cfShowModal(data.message);
				}
		    }
		});
		return false;
	}

	function fnConfirmYes() {
		document.location.href = "../member/login.jsp?next_url=" + document.location.href;
	}
	</script>
	
</head>
<body>
	<div id="wrap">
		<%@ include file="/m/include/header.jsp"  %>
		
		<div id="book_search">
        	<form name="searchForm" method="get" action="" onsubmit="return fnSearchCoupon()">
        		<input type="hidden" name="os" value="<%=os %>"/>
        		<div class="ui-input-search ui-body-inherit ui-corner-all ui-input-has-clear">
        	<%	if (isLogin) { %>
	        		<input type="text" name="coupon_no" id="coupon_no" value="" placeholder="쿠폰번호를 입력하세요" />
	        <%	} else { %>
	        		<input type="text" name="coupon_no" id="coupon_no" value="" placeholder="쿠폰번호를 입력하세요(로그인 필요)" onfocus="this.blur(); cfShowModalConfirm('로그인하시겠습니까?');"/>
	        <%	} %>
	        		<button type="submit"  value="확인">확인</button>
	        	</div>
       		</form>
       	</div>
        	
        	
		<div id="contents">
        	<ul class="listview">
<%		for (int i = 0; i < categoryList.size(); i++) { %>
<%			if ("0".equals(categoryList.get("sort2",i))) { %>
				<li class="group"><%= categoryList.get("category_name",i) %></li>
<%			} else { %>
				<li>
					<a href="./bookList.jsp?category_code=<%= categoryList.get("category_code",i)%>&os=<%=os %>" class="arrow-r">
						<%= categoryList.get("category_name",i) %>
					</a>
					<span><%= categoryList.get("book_count",i) %></span>
				</li>
<%			} %>
<%		} %>
        	</ul>

        </div>
		<%@ include file="/m/include/footer.jsp"  %>
  	</div>
</body>
</html>

